home *** CD-ROM | disk | FTP | other *** search
/ Amiga CD-Sensation: Demos Are Forever / Amiga CD-Sensation - Ausgabe 1 - Demos Are Forever (1996)(GTI - Schatztruhe)(DE)[!].iso / Big Bunch / The Rest / Starfields / ES.asm < prev    next >
Assembly Source File  |  1992-05-17  |  39KB  |  1,524 lines

  1. *\  :ts=8 bk=0
  2. *
  3. * ES.asm:    A neato star program based on some Euro code (from the group
  4. *        "Absence" I believe).
  5. *
  6. *        This code came from Portal under the name STARTOY.LZH and
  7. *        was uploaded by Greg Cunningham (author of BaudBandit).
  8. *        The program was disassembled using ReSource 4.16 (from The
  9. *        Puzzle Factory), and modified from there by me.
  10. *
  11. *        Improvements:
  12. *        o No longer Disable()s the world whle running.
  13. *        o Tossed out hard-coded custom copper list; now uses an
  14. *          Intuition screen.  (Drag it!  Amaze your friends!)
  15. *        o Uses Intuition Window to collect mouse click.
  16. *        o Now *closes* GfxBase.
  17. *        o Clipping improved.
  18. *        o Replaced 800-entry sinetable with 1024-entry table.
  19. *        o Angles and spins now forced to even values.
  20. *        o New, more traditional perspective formula.
  21. *        o Reasonably commented.
  22. *        o Busy-wait for bottom-of-frame replaced with copper
  23. *          interrupt.
  24. *        o New amazing stupendous incredible argument parser.
  25. *        o Code speed improved slightly (!)
  26. *        o Has an ARexx port!!!!!
  27. *
  28. * Some dedicated EuroHacker                91??.??
  29. * Leo L. Schwab            (415) 903-9321        9109.12
  30. *  New argument parsing                    9205.09
  31. *  New 1024-entry sinetable                9205.09
  32. *  Functional ARexx                    9205.10
  33. *  BOF copper interrupt                    9205.11
  34. */
  35.  
  36. ****************************************************************************
  37. * Documentation.
  38. *
  39. ******* ES ******************************************
  40. *
  41. *   NAME
  42. *    ES -- EuroStars
  43. *
  44. *   SYNOPSIS
  45. *    ES [MRS][XYZ] <value> [<value> ... ]
  46. *    ES B
  47. *    ES Q    (ARexx only)
  48. *
  49. *   DESCRIPTION
  50. *    ES is a starfield program based on European code that has been
  51. *    massively cleaned up and featurized.  As a result, it doesn't run
  52. *    quite as smoothly on vanilla 68000-based systems, but it's less
  53. *    likely to trash your system.
  54. *
  55. *    ES may be run from the command line or from the Workbench.  When
  56. *    you're finished looking, click the left mouse button anywhere on the
  57. *    starfield to exit.
  58. *
  59. *    ES lets you specify how the stars move and rotate.  This is done
  60. *    from the command line or from the ARexx port.  For both, the
  61. *    argument syntax is the same.
  62. *
  63. *   ARGUMENTS
  64. *    The M, R, and S operators specify star movement, rotation, and spin
  65. *    respectively.  Movement specifies how many world units the stars are
  66. *    translated each frame.  Rotation specifies a static/initial rotation
  67. *    angle.  Spin specifies the change in rotation for each frame.  The
  68. *    X, Y, and Z specifiers indicate which axes the operators are to
  69. *    apply.  Rotation angles are specified in "EuroHackerGrads."  There
  70. *    are 2048 EHG to a full 360 degree circle.
  71. *
  72. *    The MRS operators must appear before the the XYZ specifiers, and
  73. *    there may be no spaces between them.  Only one MRS operator may
  74. *    appear before a given set of XYZ specifiers.  Following the MRSXYZ
  75. *    command are the actual values to be used.
  76. *
  77. *    It's much easier to understand if you look at the examples.
  78. *
  79. *    In addition to the above, there are two additional arguments that
  80. *    may be used:
  81. *
  82. *    B:    Operate as background server.
  83. *        Ordinarily, ES will exit when you click on its screen.
  84. *        However, if you want to do extensive ARexx operations
  85. *        without user interference, this option may be specified,
  86. *        causing ES to ignore all subsequent mouse events on its
  87. *        screen.  Once backgrounded, ES cannot be un-backgrounded.
  88. *        The only way to terminate a backgrounded ES is with the
  89. *        following command:
  90. *
  91. *    Q:    Quit.
  92. *        When sent as an ARexx command, ES will exit immediately.
  93. *        This option on the CLI command line is meaningless; if
  94. *        present, the entire command line is ignored.
  95. *
  96. *   AREXX
  97. *    ES features an ARexx port.  The name of the port is EUROSTARS.
  98. *    Commands sent to this port are exactly the same as those on the
  99. *    command line.  Malformed commands are returned with RC set to
  100. *    RC_ERROR (10).
  101. *
  102. *    Commands are cumulative; that is, a move command (for example)
  103. *    remains in effect until reset by another move command for the same
  104. *    axis.  Thus, an MX command followed later by an SX command does not
  105. *    cancel the MX command.
  106. *
  107. *   EXAMPLES
  108. *    ES mx 4
  109. *        Move stars 4 units along X axis each frame.
  110. *    ES sxyz 2 -4 6
  111. *        For each frame, spin the X axis 2 EHG, the Y axis -4 EHG,
  112. *        and the Z axis 6 EHG.
  113. *    ES rx 512
  114. *        Rotate X axis 512 EHG and keep it there.
  115. *    ES rx -512 sx 2
  116. *        Start X axis rotated at -512 EHG and add 2 EHG to it each
  117. *        frame.
  118. *    ES mxz 10 0 sxyz 2 2 2
  119. *        Move 10 units along X, zero units along Z, and spin all axes
  120. *        by two EHG each frame.
  121. *    ES mxz sxyz 10 0 2 2 2
  122. *        Identical to the above.
  123. *    ES sxmxsymzsz 2 10 2 0 2
  124. *        Again, identical to the above.
  125. *
  126. *    As you can see, the syntax is very flexible.
  127. *
  128. *   NOTES
  129. *    Despite its nomenclature, the 'B' option does not fork ES into the
  130. *    background; you must use the 'Run' command.
  131. *
  132. *    The coordinate system is right-handed, X axis horizontal, Y axis
  133. *    vertical, Z axis perpendicular to the screen.  Positive rotations
  134. *    are clockwise, and are in Z,Y,X order.
  135. *
  136. *    The default startup values are:
  137. *    MX 0  MY 0  MZ 4   RX 0  RY 0  RZ 0   SX 0  SY 0  SZ 0
  138. *
  139. *   BUGS
  140. *    Slow on a 68000.  Short of Disable()ing the system or reducing the
  141. *    number of stars, this is unavoidable.
  142. *
  143. *    Malformed commands generate a diagnostic string to the CLI.  These
  144. *    strings are not available to ARexx programs.  Sigh...
  145. *
  146. *   AUTHOR
  147. *    Leo L. Schwab  --  New Technologies Group, Inc.
  148. *    BIX:        ewhac
  149. *    Portal:        ewhac
  150. *    InterNet:    ewhac@ntg.com   ..or..   ewhac@well.sf.ca.us
  151. *
  152. ****************************************************************************
  153. * Includes.
  154. *
  155.         include    'exec/types.i'
  156.         include    'exec/memory.i'
  157.         include    'graphics/gfxbase.i'
  158.         include    'hardware/intbits.i'
  159.         include    'intuition/intuition.i'
  160.         include    'libraries/dosextens.i'
  161.         include    'rexx/storage.i'
  162.         include    'rexx/errors.i'
  163.  
  164.  
  165. ****************************************************************************
  166. * A couple of simple macros.
  167. *
  168. xlib    MACRO
  169.         XREF    _LVO\1
  170.     ENDM
  171.  
  172. jsrlib    MACRO
  173.         jsr    _LVO\1(a6)
  174.     ENDM
  175.  
  176.  
  177. ****************************************************************************
  178. * External references.
  179. *
  180.         xlib    AllocMem
  181.         xlib    FreeMem
  182.         xlib    AllocSignal
  183.         xlib    FreeSignal
  184.         xlib    AddIntServer
  185.         xlib    RemIntServer
  186.         xlib    OpenLibrary
  187.         xlib    CloseLibrary
  188.         xlib    Forbid
  189.         xlib    Permit
  190.         xlib    WaitPort
  191.         xlib    PutMsg
  192.         xlib    GetMsg
  193.         xlib    ReplyMsg
  194.         xlib    AddPort
  195.         xlib    RemPort
  196.         xlib    FindTask
  197.         xlib    Signal
  198.         xlib    Wait
  199.         xlib    OpenScreen
  200.         xlib    OpenWindow
  201.         xlib    CloseScreen
  202.         xlib    CloseWindow
  203.         xlib    SetPointer
  204.         xlib    MakeScreen
  205.         xlib    GetScreenData
  206.         xlib    RethinkDisplay
  207.         xlib    QueryOverscan
  208.         xlib    LoadRGB4
  209.         xlib    FreeCopList
  210.         xlib    UCopperListInit
  211.         xlib    CWait
  212.         xlib    CMove
  213.         xlib    CBump
  214.         xlib    Output
  215.         xlib    Write
  216.         xlib    CreateProc
  217.         xlib    Lock
  218.  
  219.         xref    _intreq
  220.  
  221.  
  222. ****************************************************************************
  223. * Public symbols (primarily for debugging).
  224. *
  225.         xdef    Transform
  226.         xdef    NextStar
  227.         xdef    StarSeg
  228.         xdef    MoveStars
  229.         xdef    DrawStars
  230.         xdef    SinCos
  231.         xdef    ParseArgs
  232.  
  233.  
  234. ****************************************************************************
  235. * Symbol Definitions
  236. *
  237. MINBOX        equ    -450
  238. MAXBOX        equ    450
  239. BOXRANGE    equ    MAXBOX-MINBOX+1
  240.  
  241. MAGIC        equ    $10000        ; 256 << 8
  242. ZPULL        equ    780
  243.  
  244. SCRWIDE        equ    352
  245. SCRHIGH        equ    230
  246.  
  247. SPRBUFSIZ    equ    12
  248.  
  249.  
  250. ****************************************************************************
  251. * And now for the code!
  252. *
  253.         section    EuroStars,code
  254.  
  255. CreatedSix
  256.     ;------    Test CLI vs. Workbench
  257.         bsr    ClearBSS    ; Initialize uninitialized data
  258.  
  259.         moveq    #0,d7        ; No error
  260.         move.l    a0,a2        ; Save CLI command line data
  261.         move.l    d0,d2
  262.  
  263.         move.l    (4).w,a6
  264.         sub.l    a1,a1        ; Find ourselves
  265.         jsrlib    FindTask
  266.         move.l    d0,mpsigtask
  267.         move.l    d0,a0
  268.         tst.l    pr_CLI(a0)    ; Are we a CLI?
  269.         beq.s    WBench        ; No, don't parse command line.
  270.  
  271.     ;------    CLI startup.  Parse arguments.
  272.         move.l    a2,a0        ; Restore CLI command data
  273.         move.l    d2,d0
  274.         clr.b    0(a0,d0.l)    ; Force NULL at end of command line
  275.         bsr    ParseArgs
  276.         move.l    d0,d7        ; Save error string (it's easier
  277.         bra.s    OpenDOS        ;  this way.  Trust me.)
  278.  
  279.     ;------    Workbench startup.  Get startup message.
  280. WBench        lea    pr_MsgPort(a0),a2
  281.         move.l    a2,a0
  282.         jsrlib    WaitPort
  283.         move.l    a2,a0
  284.         jsrlib    GetMsg
  285.         move.l    d0,WBStartMsg
  286.  
  287.     ;------    Open DOS.
  288. OpenDOS        move.l    (4).w,a6
  289.         lea    DOSName(pc),a1
  290.         moveq    #0,d0
  291.         jsrlib    OpenLibrary
  292.         move.l    d0,DOSBase
  293.         beq    err_dos
  294.  
  295.     ;------    Now then, did the parser return an error?
  296.         move.l    d7,d0
  297.         ble.s    1$        ; (Ignore 'QUIT')
  298.         bsr    PrintCLIStr    ; Print the error
  299.         bra    err_mem        ; Exit (closing DOS)
  300. 1$
  301.     ;------    Allocate memory for blank sprite.
  302.         moveq    #SPRBUFSIZ,d0
  303.         move.l    #MEMF_CHIP!MEMF_CLEAR,d1
  304.         jsrlib    AllocMem
  305.         move.l    d0,sprdat
  306.         beq    err_mem
  307.  
  308.     ;------    Allocate signal for message port.
  309.         moveq    #-1,d0
  310.         jsrlib    AllocSignal
  311.         move.b    d0,mpsigbit
  312.         bmi    err_signal
  313.  
  314.     ;------    Open Graphics
  315.         lea    GfxName(pc),a1
  316.         moveq    #0,d0
  317.         jsrlib    OpenLibrary
  318.         move.l    d0,GBase
  319.         beq    err_gfx
  320.  
  321.     ;------    Open Intuition
  322.         lea    IntuiName(pc),a1
  323.         moveq    #0,d0
  324.         jsrlib    OpenLibrary
  325.         move.l    d0,IBase
  326.         beq    err_intui
  327.  
  328.     ;------    Open screen
  329.         move.l    d0,a6
  330.         lea    scr_def(pc),a0
  331.         jsrlib    OpenScreen
  332.         move.l    d0,scrptr
  333.         beq    err_scr
  334.         move.l    d0,a2
  335.  
  336.     ;------    Open window on screen
  337.         lea    windef(pc),a0
  338.         jsrlib    OpenWindow
  339.         move.l    d0,winptr
  340.         beq    err_win
  341.  
  342.     ;------    Set invisible pointer.
  343.         move.l    d0,a0
  344.         move.l    sprdat(pc),a1
  345.         moveq    #0,d0
  346.         moveq    #0,d1
  347.         moveq    #0,d2
  348.         moveq    #0,d3
  349.         jsrlib    SetPointer
  350.  
  351.     ;------    Set local bitplane pointers.
  352.         move.l    sc_BitMap+bm_Planes+0(a2),Plane1ptr
  353.         move.l    sc_BitMap+bm_Planes+4(a2),Plane2ptr
  354.  
  355.     ;------    Shove Screen's ViewPort into a nice-ish overscan position.
  356.     ;------    We have to do this differently based on OS revision.
  357.         lea    XBuff,a3
  358.         cmp.w    #37,LIB_VERSION(a6)    ; What version?
  359.         blt.s    OScan1_3
  360.  
  361.     ;------    Do 2.0 centering.  A3 is used as Rectangle structure pointer.
  362.         move.l    a3,a1
  363.         moveq    #OSCAN_TEXT,d0
  364.         sub.l    a0,a0        ; Zero is LORES_KEY
  365.         jsrlib    QueryOverscan
  366.  
  367.         move.w    #SCRWIDE,d0    ; Compute difference in sizes
  368.         sub.w    ra_MaxX(a3),d0    ;  between standard screen and ours.
  369.         add.w    ra_MinX(a3),d0
  370.         move.w    #SCRHIGH,d1    ; SCRHIGH - (MaxY - MinY)
  371.         sub.w    ra_MaxY(a3),d1
  372.         add.w    ra_MinY(a3),d1
  373.         asr.w    #1,d0
  374.         asr.w    #1,d1
  375.         sub.w    d0,sc_ViewPort+vp_DxOffset(a2)    ; Shift screen
  376.         sub.w    d1,sc_ViewPort+vp_DyOffset(a2)
  377.         bra.s    AddBOF
  378.  
  379.     ;------    Do 1.3 centering.  A3 is used as screen buffer pointer.
  380. OScan1_3    move.l    a3,a0        ; Screen buffer
  381.         move.l    #sc_SIZEOF,d0    ; bufsiz
  382.         moveq    #WBENCHSCREEN,d1    ; Screen type
  383.         sub.l    a1,a1        ; NULL
  384.         jsrlib    GetScreenData    ; Tell me about the Workbench screen
  385.  
  386.         move.w    #SCRWIDE,d0    ; Skate screen acto WBench size
  387.         move.w    sc_ViewPort+vp_DWidth(a3),d1
  388.         btst.b    #7,sc_ViewPort+vp_Modes(a3)    ; Check HIRES bit
  389.         beq.s    2$        ; HIRES?
  390.         asr.w    #1,d1        ; Yes, divide width by two
  391. 2$
  392.         sub.w    d1,d0
  393.         asr.w    #1,d0        ; Divide difference by two
  394.         sub.w    d0,sc_ViewPort+vp_DxOffset(a2)    ; Shift screen
  395.  
  396.         move.w    #SCRHIGH,d0
  397.         move.w    sc_ViewPort+vp_DHeight(a3),d1
  398.         btst.b    #2,sc_ViewPort+vp_Modes+1(a3)    ; Check LACE bit
  399.         beq.s    3$        ; LACE?
  400.         asr.w    #1,d1        ; Yes, divide height by two
  401. 3$
  402.         sub.w    d1,d0
  403.         asr.w    #1,d0
  404.         sub.w    d0,sc_ViewPort+vp_DyOffset(a2)    ; Shift screen
  405.  
  406.     ;------    Add Bottom-of-frame copper interrupt.
  407. AddBOF        lea    MyCopList,a3
  408.         move.l    a3,sc_ViewPort+vp_UCopIns(a2)    ; vp->UCopIns = cl;
  409.         move.l    a3,a0        ; CINIT (cl, 4);
  410.         moveq    #4,d0
  411.         move.l    GBase(pc),a6
  412.         jsrlib    UCopperListInit
  413.  
  414.         move.l    a3,a1        ; CWAIT (cl, SCRHIGH, 0);
  415.         move.l    #SCRHIGH,d0
  416.         moveq    #0,d1
  417.         jsrlib    CWait
  418.         move.l    a3,a1
  419.         jsrlib    CBump
  420.  
  421.         move.l    a3,a1        ; CMOVE (cl, intreq,
  422.         move.l    #_intreq,d0    ;     INTF_SETCLR | INTF_COPER);
  423.         move.l    #INTF_SETCLR!INTF_COPER,d1
  424.         jsrlib    CMove
  425.         move.l    a3,a1
  426.         jsrlib    CBump
  427.  
  428.         move.l    a3,a1        ; CEND (cl);
  429.         move.l    #10000,d0
  430.         move.l    #255,d1
  431.         jsrlib    CWait
  432.         move.l    a3,a1        ; Not sure this is necessary, but the
  433.         jsrlib    CBump        ;  gfxmacros.h macro does it...
  434.  
  435.     ;------    Recompose display.
  436.         move.l    a2,a0        ; Screen still in A2
  437.         move.l    IBase(pc),a6
  438.         jsrlib    MakeScreen
  439.         jsrlib    RethinkDisplay
  440.  
  441.     ;------    Load colors.
  442.         lea    sc_ViewPort(a2),a0
  443.         lea    colors(pc),a1
  444.         moveq    #4,d0
  445.         move.l    GBase(pc),a6
  446.         jsrlib    LoadRGB4
  447.  
  448.     ;------    Create sub-process to actually render stars.
  449.         move.l    mpsigtask(pc),a0
  450.         moveq    #0,d2
  451.         move.b    LN_PRI(a0),d2    ; Priority
  452.         subq.l    #1,d2        ; (Nudge *BELOW* creator)
  453.         lea    StarSeg(pc),a0
  454.         move.l    a0,d3        ; SegList pointer
  455.         lsr.l    #2,d3        ; (Convert to BPTR)
  456.         lea    ESName(pc),a0
  457.         move.l    a0,d1        ; Process name
  458.         move.l    #4096,d4    ; Stack size
  459.         move.l    DOSBase(pc),a6
  460.         jsrlib    CreateProc
  461.         tst.l    d0
  462.         beq    err_proc
  463.  
  464.     ;------    Launch subprocess with startup message.
  465.         move.l    d0,a0
  466.         lea    startmsg(pc),a1
  467.         move.l    (4).w,a6
  468.         jsrlib    PutMsg
  469.  
  470.     ;------    Publish message port.
  471.         lea    mport(pc),a1
  472.         jsrlib    AddPort
  473.  
  474.  
  475.     ;------    Wait for ARexx and Intuition events.
  476.         bsr    HandleEvents
  477.  
  478.  
  479.     ;------    Remove port and flush all pending messages.
  480.         jsrlib    Forbid        ; STOP!
  481.         lea    mport(pc),a2
  482.         move.l    a2,a1
  483.         jsrlib    RemPort        ; Pull port from list
  484.         moveq    #RC_FATAL,d2
  485.  
  486. flushloop    move.l    a2,a0
  487.         jsrlib    GetMsg        ; Get message, if any
  488.         tst.l    d0
  489.         beq.s    1$        ; No message, leave loop
  490.         move.l    d0,a1
  491.         move.l    d2,rm_Result1(a1)    ; Die die die
  492.         clr.l    rm_Result2(a1)
  493.         jsrlib    ReplyMsg    ; Reply failed message
  494.         bra.s    flushloop
  495. 1$
  496.         jsrlib    Permit        ; Okay, go ahead.
  497.  
  498.     ;------    Send kill signal to stars process.
  499.         moveq    #0,d0
  500.         bset    #SIGBREAKB_CTRL_C,d0
  501.         move.l    StarTask(pc),a1        ; RACE!!  Might not be set!
  502.         jsrlib    Signal
  503.  
  504.     ;------    Wait for startup message to return.
  505.         lea    mport(pc),a0
  506.         jsrlib    WaitPort
  507.  
  508.  
  509.     ;------    Cleanup and exit.
  510. err_proc    move.l    GBase(pc),a6    ; Delete UCopList by hand
  511.         move.l    scrptr(pc),a0    ;  (required for 1.3)
  512.         lea    sc_ViewPort+vp_UCopIns(a0),a0
  513.         move.l    (a0),a1
  514.         clr.l    (a0)        ; Keep system from freeing it, too
  515.         move.l    ucl_FirstCopList(a1),a0
  516.         jsrlib    FreeCopList
  517.  
  518.         move.l    IBase(pc),a6    ; Close window
  519.         move.l    winptr(pc),a0
  520.         jsrlib    CloseWindow
  521. err_win        move.l    scrptr(pc),a0
  522.         jsrlib    CloseScreen
  523. err_scr        move.l    a6,a1
  524.         move.l    (4).w,a6
  525.         jsrlib    CloseLibrary    ; Close Intuition
  526. err_intui    move.l    GBase(pc),a1
  527.         jsrlib    CloseLibrary    ; Close Graphics
  528. err_gfx        moveq    #0,d0
  529.         move.b    mpsigbit(pc),d0
  530.         jsrlib    FreeSignal    ; Free msgport signal
  531. err_signal    move.l    sprdat(pc),a1
  532.         moveq    #SPRBUFSIZ,d0
  533.         jsrlib    FreeMem
  534. err_mem        move.l    DOSBase(pc),a1
  535.         jsrlib    CloseLibrary
  536. err_dos
  537.         move.l    WBStartMsg(pc),d0    ; Reply Workbench startup
  538.         beq.s    xit            ;  if present.
  539.  
  540.         move.l    d0,a1
  541.         jsrlib    ReplyMsg
  542.         clr.l    d0
  543.  
  544. xit        rts
  545.  
  546.  
  547. ****************************************************************************
  548. * ARexx message and window event processing loop.
  549. *
  550. HandleEvents
  551.     ;------    Compute signal flag for window port.
  552.         moveq    #0,d2
  553.         move.l    winptr(pc),a0
  554.         move.l    wd_UserPort(a0),a0
  555.         move.b    MP_SIGBIT(a0),d0
  556.         bset.l    d0,d2
  557.  
  558.     ;------    Compute signal flag for ARexx port.
  559.         move.b    mpsigbit(pc),d0
  560.         bset.l    d0,d2
  561.  
  562.     ;------    Wait for something to happen.
  563. eventloop    move.l    d2,d0
  564.         jsrlib    Wait
  565.  
  566.     ;------    Check for ARexx messages.
  567.         moveq    #RC_ERROR,d3
  568.  
  569. 0$        lea    mport(pc),a0
  570.         jsrlib    GetMsg
  571.         tst.l    d0        ; Message present?
  572.         beq.s    9$        ; No, fall off
  573.  
  574.         move.l    d0,a2
  575.         move.l    ARG0(a2),a0    ; Get argument string
  576.         bsr    ParseArgs    ; Parse it
  577.         move.l    d0,d7        ; Was there an error?
  578.         ble.s    1$        ; No
  579.  
  580.         move.l    d3,rm_Result1(a2)    ; Yes, store error
  581.         bra.s    2$
  582.  
  583. 1$        clr.l    rm_Result1(a2)
  584. 2$        clr.l    rm_Result2(a2)    ; Result2 always NULL
  585.         move.l    a2,a1
  586.         jsrlib    ReplyMsg    ; Send message back
  587.         bra.s    0$        ; Next message, please
  588. 9$
  589.     ;------    Was that parser return a REXX request for death?
  590.         tst.l    d7
  591.         bmi.s    Rexxit        ; Why, yes it was!
  592.  
  593.     ;------    Check for window events.
  594.         move.l    winptr(pc),a0
  595.         move.l    wd_UserPort(a0),a0
  596.         jsrlib    GetMsg        ; Check port
  597.         tst.l    d0        ; Something there?
  598.         beq.s    eventloop    ; No, go to sleep
  599.         move.l    d0,a1        ; Yup, reply it
  600.         jsrlib    ReplyMsg
  601.  
  602.     ;------    Window event arrived.  If we are a background server, ignore
  603.     ;------    the event.  Elsewise, return.
  604.         move.w    BackServ(pc),d0    ; Just to set flags
  605.         bne.s    eventloop
  606.  
  607. Rexxit        rts            ; User wants us dead, dammit.
  608.  
  609.  
  610. ****************************************************************************
  611. * Welcome to the actual stars code.
  612. *
  613.         cnop    0,4
  614.  
  615. StarSeg        dc.l    0        ; Phony NextSeg pointer
  616.  
  617.     ;------    Entry point.
  618.         move.l    (4).w,a6
  619.         sub.l    a1,a1
  620.         jsrlib    FindTask        ; Get pointer to this task.
  621.         move.l    d0,StarTask        ; Store
  622.         move.l    d0,a0
  623.         lea    pr_MsgPort(a0),a2    ; Get pointer to MsgPort
  624.  
  625.     ;------    Wait for startup message.
  626.         move.l    a2,a0
  627.         jsrlib    WaitPort
  628.         move.l    a2,a0
  629.         jsrlib    GetMsg
  630.         move.l    d0,StarMsg
  631.  
  632.     ;------    Compute sigmask.
  633.         moveq    #0,d0
  634.         bset.l    #SIGBREAKB_CTRL_C,d0
  635.         bset.l    #SIGBREAKB_CTRL_F,d0    ; BOF will happen here.
  636.         move.l    d0,StarSigMask
  637.  
  638.     ;------    Install interrupt server.
  639.         moveq    #INTB_COPER,d0
  640.         lea    BOFintrnode(pc),a1
  641.         jsrlib    AddIntServer
  642.  
  643.     ;------    Main star loop.
  644. mainloop    bsr    AddSpins
  645.         bsr    Transform
  646.         bsr.s    MoveStars
  647.  
  648.         move.l    StarSigMask(pc),d0
  649.         jsrlib    Wait        ; Wait for BOF or kill signal
  650.         move.l    d0,StarSigs
  651.  
  652.         bsr    EraseStars    ; Do this in any case
  653.         bsr    DrawStars
  654.  
  655.         move.l    StarSigs(pc),d0
  656.         btst.l    #SIGBREAKB_CTRL_C,d0
  657.         beq.s    mainloop
  658.  
  659.     ;------    Got kill signal from above.  Remove interrupt server,
  660.     ;------    reply startup and exit.
  661.         jsrlib    Forbid        ; HA!  MINE!
  662.         moveq    #INTB_COPER,d0
  663.         lea    BOFintrnode(pc),a1
  664.         jsrlib    RemIntServer
  665.  
  666.         move.l    StarMsg(pc),a1
  667.         jmp    _LVOReplyMsg(a6)    ; Poof!  Bye...
  668.  
  669.  
  670.  
  671. ****************************************************************************
  672. * Move the stars
  673. *
  674. MoveStars    lea    XCoords(pc),a0
  675.         lea    YCoords(pc),a1
  676.         lea    ZCoords(pc),a2
  677.         move.w    delta_x(pc),d0
  678.         move.w    delta_y(pc),d1
  679.         move.w    delta_z(pc),d2
  680.         move.w    #BOXRANGE,d4
  681.         move.w    NumStars(pc),d7
  682.  
  683. 0$        move.w    (a0),d3
  684.         add.w    d0,d3        ; Add move delta
  685.         cmp.w    #MAXBOX,d3    ; Too big?
  686.         bgt.s    1$
  687.         cmp.w    #MINBOX,d3    ; Too small?
  688.         bge.s    2$
  689.         add.w    d4,d3        ; Wrap up
  690.         bra.s    2$
  691. 1$        sub.w    d4,d3        ; Wrap down
  692. 2$        move.w    d3,(a0)+
  693.  
  694.         move.w    (a1),d3
  695.         add.w    d1,d3
  696.         cmp.w    #MAXBOX,d3
  697.         bgt.s    11$
  698.         cmp.w    #MINBOX,d3
  699.         bge.s    22$
  700.         add.w    d4,d3
  701.         bra.s    22$
  702. 11$        sub.w    d4,d3
  703. 22$        move.w    d3,(a1)+
  704.  
  705.         move.w    (a2),d3
  706.         add.w    d2,d3
  707.         cmp.w    #MAXBOX,d3
  708.         bgt.s    111$
  709.         cmp.w    #MINBOX,d3
  710.         bge.s    222$
  711.         add.w    d4,d3
  712.         bra.s    222$
  713. 111$        sub.w    d4,d3
  714. 222$        move.w    d3,(a2)+
  715.  
  716.         dbra    d7,0$
  717.  
  718.         rts
  719.  
  720.  
  721. ****************************************************************************
  722. * Star rendering routines.
  723. *
  724. EraseStars    moveq    #0,d0
  725.         move.l    Plane1ptr(pc),a1
  726.         move.l    Plane2ptr(pc),a2
  727.         lea    PlaneOffsets,a4
  728.         move.w    NumStars(pc),d7
  729. 1$        move.w    (a4)+,d1
  730.         move.w    d0,0(a1,d1.w)    ; Blast entire word.
  731.         move.w    d0,0(a2,d1.w)
  732.         dbra    d7,1$
  733.  
  734.         rts
  735.  
  736.  
  737. DrawStars    lea    XBuff,a0
  738.         lea    YBuff,a1
  739.         lea    PlaneOffsets,a3
  740.         lea    ZBuff,a5
  741.         move.l    Plane1ptr(pc),a2
  742.         move.l    Plane2ptr(pc),a4
  743.         move.w    NumStars(pc),d7
  744.         move.w    #SCRHIGH-1,d4
  745.         move.w    #SCRWIDE-1,d5
  746.         move.w    #$8000,d6
  747. NextDraw    move.w    (a1)+,d0    ; Load and check Y value
  748.         bmi.s    clipped
  749.         cmp.w    d4,d0
  750.         bgt.s    clipped
  751.  
  752.         move.w    (a0),d1        ; Load and check X value
  753.         bmi.s    clipped
  754.         cmp.w    d5,d1
  755.         bgt.s    clipped
  756.  
  757.         move.w    d1,d2
  758.         and.b    #15,d1
  759.         and.w    #$FFF0,d2
  760.         lsr.w    #3,d2
  761.         move.w    d6,d3
  762.         ror.w    d1,d3
  763.         mulu    #SCRWIDE/8,d0    ; BytesPerRow
  764.         add.w    d0,d2
  765.         move.w    d2,(a3)+
  766.         cmp.w    #-176,(a5)    ; Z closer than this?
  767.         ble.s    1$        ; No, draw just plane 1 (dim)
  768.  
  769.         or.w    d3,0(a4,d2.w)    ; This plane definitely gets written
  770.         cmp.w    #130,(a5)    ; Very close?
  771.         ble.s    2$        ; No
  772. 1$        or.w    d3,0(a2,d2.w)    ;    Yes; draw brightest value
  773. 2$        addq.w    #2,a5
  774.         addq.w    #2,a0    ; No, you can't get rid of this easily...
  775.         dbra    d7,NextDraw
  776.  
  777.         rts
  778.  
  779. clipped        clr.w    (a3)+
  780.         addq.w    #2,a5
  781.         addq.w    #2,a0
  782.         dbra    d7,NextDraw
  783.  
  784.         rts
  785.  
  786.  
  787. ****************************************************************************
  788. * The Biggie!
  789. * Transform all points, rotating about Z, Y, and X axes (in that order).
  790. * Those of you looking for a general matrix multiply here won't find it.
  791. * These are simple two dimensional rotations applied one at a time.
  792. * The sine/cosine table uses 8.8 fixed point notation.  The numbers in the
  793. * coordinates array are straight integers.
  794. *
  795. Transform    lea    CurrentSinCos(pc),a4
  796.         move.w    theta_x(pc),d0
  797.         bsr    SinCos
  798.         move.w    d0,(a4)
  799.         move.w    d1,2(a4)
  800.         move.w    theta_y(pc),d0
  801.         bsr    SinCos
  802.         move.w    d0,4(a4)
  803.         move.w    d1,6(a4)
  804.         move.w    theta_z(pc),d0
  805.         bsr    SinCos
  806.         move.w    d0,8(a4)
  807.         move.w    d1,10(a4)
  808.         lea    XCoords(pc),a0
  809.         lea    YCoords(pc),a1
  810.         lea    ZCoords(pc),a2
  811.         lea    XBuff,a3
  812.         move.w    NumStars(pc),d4
  813.         move.l    #MAGIC,d2    ; 256 as an 8.8 fixed point num.
  814.         move.w    #ZPULL,d3    ; "Pull out"
  815.  
  816.     ;------    Perform rotations.
  817. NextStar    move.w    (a0),d5        ; X
  818.         muls    10(a4),d5    ;   * cos(z)
  819.         move.w    (a1),d1        ; Y
  820.         muls    8(a4),d1    ;   * sin(z)
  821.         sub.l    d1,d5        ; == X cos(z) - Y sin(z) == X'    D5
  822.         lsr.l    #8,d5
  823.         move.w    (a0)+,d6    ; X
  824.         muls    8(a4),d6    ;   * sin(z)
  825.         move.w    (a1)+,d1    ; Y
  826.         muls    10(a4),d1    ;   * cos(z)
  827.         add.l    d1,d6        ; == X sin(z) + Y cos(z) == Y'    D6
  828.         lsr.l    #8,d6    ; Rotation about Z axis complete.
  829.  
  830.         move.w    (a2),d7        ; Z
  831.         muls    6(a4),d7    ;   * cos(y)
  832.         move.w    4(a4),d1    ; sin(y)
  833.         muls    d5,d1        ;     * X'
  834.         sub.l    d1,d7        ; == Z cos(y) - X' sin(y) == Z'   D7
  835.         lsr.l    #8,d7
  836.         move.w    (a2)+,d1    ; Z
  837.         muls    4(a4),d1    ;   * sin(y)
  838.         muls    6(a4),d5    ; X' * cos(y)
  839.         add.l    d1,d5        ; == X' cos(y) + Z sin(y) == X''  D5
  840.         lsr.l    #8,d5    ; Rotation about Y axis complete.
  841.  
  842.         move.w    d6,d0        ; Y'
  843.         muls    2(a4),d6    ;    * cos(x)
  844.         move.w    d7,d1        ; Z'
  845.         muls    (a4),d1        ;    * sin(z)
  846.         sub.l    d1,d6        ; == Y' cos(x) - Z' sin(x) == Y'' D6
  847.         lsr.l    #8,d6
  848.         muls    (a4),d0        ; Y' * sin(x)
  849.         muls    2(a4),d7    ; Z' * cos(x)
  850.         add.l    d0,d7        ; == Y' sin(x) + Z' cos(x) == Z'' D7
  851.         lsr.l    #8,d7    ; Rotation about X axis complete.
  852.  
  853. * Before I got to this, the perspective formula was:
  854. *
  855. *     1000 - Z
  856. *    ----------
  857. *      780 - Z
  858. *
  859. * I ran this through a spreadsheet (Thanks, Mike!) and found that, yes, it
  860. * does yield a hyperbolic curve (which is correct).  However, it was so
  861. * alien that I decided to re-work it into a more traditional form found in
  862. * most of my graphics books.  The scalar is now:
  863. *
  864. *        MAGIC
  865. *    -------------
  866. *    - (Z - ZPULL)
  867. *
  868. * This is closer to what you'll find in the graphics books.  The subtraction
  869. * from Z is to "pull" the stars away from the camera (which is at Z == 0) so
  870. * that they'll be visible.  The negation effectively flips the Z axis, which
  871. * makes the calculation easier (trust me).  MAGIC and ZPULL are currently
  872. * set to 256 and 780 respectively.  The 256 is a number I pulled out of
  873. * Thin Air.  (So's the 780, for that matter...)  Feel free to play with them
  874. * to see what happens.
  875. *
  876.         move.w    d7,$258(a3)    ; ZBuff store (for pixel brightness)
  877.  
  878.         move.l    d2,d0        ; 256 (pre-formatted)
  879.         move.w    d3,d1        ; 780
  880.         sub.w    d7,d1        ;     - Z
  881.         ble.s    BehindCamera
  882.         divs    d1,d0        ; == 256 / -(Z - 780)
  883.         bvs.s    BehindCamera    ; Shunt wild division
  884.  
  885.         move.w    d6,d1        ; Y
  886.         muls    d0,d1        ;    * 256 / -(Z - 780)
  887.         lsr.l    #8,d1
  888.         add.w    #115,d1        ; + center_screen_y
  889.         move.w    d1,$12C(a3)    ; YBuff store
  890.  
  891.         move.w    d5,d1        ; X
  892.         muls    d0,d1        ;    * 256 / -(Z - 780)
  893.         lsr.l    #8,d1
  894.         add.w    #176,d1        ; + center_screen_x
  895.         move.w    d1,(a3)+    ; XBuff store
  896.         dbra    d4,NextStar
  897.  
  898.         rts
  899.  
  900.     ;------    Whoops!  Behind the camera.  Force an invisible point.
  901. BehindCamera    moveq    #-1,d1
  902.         move.w    d1,$12C(a3)    ; YBuff store
  903.         move.w    d1,(a3)+    ; XBuff store
  904.         dbra    d4,NextStar
  905.  
  906.         rts
  907.  
  908.  
  909. ****************************************************************************
  910. * Sine/Cosine calculator.  Nothing amazing here, just a table lookup.
  911. * D0: Angle (360 deg. == 1600)
  912. * D0 is used directly as offset into sine table; MUST be even, lest Bad
  913. * Things happen.
  914. *
  915. * Returns sine in D0, cosine in D1.
  916. *
  917. SinCos        lea    SineTable(pc),a5
  918.         move.w    d0,d2
  919.         move.w    0(a5,d0.w),d0    ; Fetch sine
  920.         cmp.w    #2048-512,d2
  921.         ble.s    1$
  922.         sub.w    #2048-512,d2
  923.         bra.s    2$
  924.  
  925. 1$        add.w    #512,d2
  926. 2$        move.w    0(a5,d2.w),d1    ; Fetch cosine
  927.         rts
  928.  
  929.  
  930. ****************************************************************************
  931. * Add spins to current rotation angles.  Clip to 360° circle.
  932. *
  933. AddSpins    move.w    #2048-1,d1    ; 360° == 2048 EHG
  934.         lea    theta_x(pc),a0
  935.         lea    spin_x(pc),a1
  936.  
  937.         move.w    (a0),d0        ; Get angle
  938.         add.w    (a1)+,d0    ; Add spin
  939.         and.w    d1,d0        ; Clip to 360°
  940.         move.w    d0,(a0)+    ; Store it back
  941.  
  942.         move.w    (a0),d0
  943.         add.w    (a1)+,d0
  944.         and.w    d1,d0
  945.         move.w    d0,(a0)+
  946.  
  947.         move.w    (a0),d0
  948.         add.w    (a1),d0
  949.         and.w    d1,d0
  950.         move.w    d0,(a0)
  951.  
  952.         rts
  953.  
  954.  
  955.  
  956. ****************************************************************************
  957. * New ParseArgs.  More flexible!  Less filling!
  958. * Added 9202.20        Finished 9205.09
  959. *
  960. *    A0:  Argument string.
  961. *
  962. *    As the options are parsed, the destination address of the value is
  963. *    pushed on a queue.  As values are acquired, the address is pulled,
  964. *    and the value stored there.  Imbalances are checked and reported.
  965. *
  966. * SYNOPSIS
  967. *    [MRS][XYZ] <value> [ <value> ... ]
  968. *
  969. *    Only one M, R, or S qualifier may accompany XYZ specifiers.  They
  970. *    may be specified in any order, and the values need not immediately
  971. *    follow them.
  972. *
  973. * OPTIONS
  974. *    M: Move; specify translation
  975. *    R: Rotate; specify initial rotation
  976. *    S: Spin; specify spin velocities
  977. *
  978.  
  979. ParseArgs    movem.l    d2/d7/a2-a5,-(sp)
  980.         sub.l    a3,a3        ; Mode (NULL)
  981.         move.l    sp,a4        ; Stacksave
  982.         move.l    sp,a5        ; Pop pointer
  983.  
  984.     ;------    Copy active variables to workspace.
  985.         lea    delta_x(pc),a1
  986.         lea    wrk_delta(pc),a2
  987.         move.l    (a1)+,(a2)+
  988.         move.l    (a1)+,(a2)+
  989.         move.l    (a1)+,(a2)+
  990.         move.l    (a1)+,(a2)+
  991.         move.w    (a1),(a2)
  992.  
  993.     ;------    Main parsing loop.
  994. getchar        moveq    #0,d0
  995.         move.b    (a0)+,d0    ; getchar()
  996.         beq    EndOfString
  997.         cmp.b    #'a',d0        ; Lower case?
  998.         blo.s    0$
  999.         sub.b    #'a'-'A',d0    ; Convert to upper case
  1000. 0$
  1001.     ;------    Test for whitespace.
  1002.         cmp.b    #' ',d0
  1003.         beq.s    whitespace
  1004.         cmp.b    #9,d0        ; TAB
  1005.         beq.s    whitespace
  1006.         cmp.b    #10,d0        ; Newline
  1007.         beq.s    whitespace
  1008.  
  1009.     ;------    Test for numeric.
  1010.         cmp.b    #'-',d0        ; Leading minus
  1011.         beq.s    numeric
  1012.         cmp.b    #'0',d0
  1013.         blo.s    3$
  1014.         cmp.b    #'9',d0
  1015.         bls.s    numeric
  1016. 3$
  1017.     ;------    Test for [B]ackground command.
  1018.         cmp.b    #'B',d0
  1019.         bne.s    1$
  1020.         move.w    d0,BackServ    ; All it has to be is non-zero
  1021.         bra    UnWindOK    ; Ignore rest of string
  1022. 1$
  1023.     ;------    Test for [Q]uit command.
  1024.         cmp.b    #'Q',d0
  1025.         bne.s    2$
  1026.         moveq    #-1,d0        ; Tell upstairs we need to quit
  1027.         bra    UnWind        ; Ignore rest of string
  1028. 2$
  1029.     ;------    Test for '?' help.
  1030.         moveq    #ERR_HELP,d7
  1031.         cmp.b    #'?',d0
  1032.         beq    ParseError
  1033.  
  1034.     ;------    Test for 'XYZ'.
  1035.         cmp.b    #'X',d0
  1036.         blo.s    4$
  1037.         cmp.b    #'Z',d0
  1038.         bls.s    GotXYZ
  1039. 4$
  1040.     ;------    Test for 'MRS'; set mode if present.
  1041.         cmp.b    #'M',d0
  1042.         bne.s    11$
  1043.         lea    wrk_delta(pc),a3    ; Set mode
  1044.         bra.s    getchar
  1045. 11$
  1046.         cmp.b    #'R',d0
  1047.         bne.s    22$
  1048.         lea    wrk_theta(pc),a3    ; Set mode
  1049.         bra.s    getchar
  1050. 22$
  1051.         cmp.b    #'S',d0
  1052.         bne    33$
  1053.         lea    wrk_spin(pc),a3        ; Set mode
  1054.         bra    getchar
  1055. 33$
  1056.     ;------    Dunno what this is; error.
  1057.         moveq    #ERR_SYNTAX,d7
  1058.         bra    ParseError
  1059.  
  1060.  
  1061.     ;------    Process whitespace.
  1062. whitespace    sub.l    a3,a3        ; NULL out mode
  1063.         bra    getchar
  1064.  
  1065.  
  1066.     ;------    Process numerics.
  1067. numeric        subq.w    #1,a0        ; ungetchar()
  1068.         bsr.s    GatherNum    ; Parsed value returned in D0
  1069.  
  1070.         moveq    #ERR_EXTRAVAL,d7
  1071.         cmpa.l    sp,a5        ; Are there values yet to be poked?
  1072.         beq    ParseError    ; Nope, too many values.
  1073.         move.l    -(a5),a1    ; Get address to poke
  1074.         move.w    d0,(a1)        ; Write value.
  1075.  
  1076.         bra    getchar
  1077.  
  1078.  
  1079.     ;------    Process presence of 'XYZ'.
  1080. GotXYZ        moveq    #ERR_NOMODE,d7
  1081.         move.l    a3,d1        ; Mode set?
  1082.         beq    ParseError    ; No, user forgot MRS qualifier
  1083.  
  1084.         sub.b    #'X',d0        ; Compute index
  1085.         add.w    d0,d0        ; Compute word offset
  1086.         add.l    a3,d0        ; Add "mode" to get final address
  1087.         move.l    d0,-(sp)    ; Push address
  1088.         bra    getchar
  1089.  
  1090.  
  1091.     ;------    End of string; perform sanity checks and return.
  1092. EndOfString    moveq    #ERR_MISSINGVAL,d7
  1093.         cmpa.l    sp,a5        ; Is stack empty?
  1094.         bne.s    ParseError
  1095.  
  1096.     ;------    Force angles and rotations to even values.
  1097.         moveq    #-2,d0        ; 0xFFFE
  1098.         bclr    #16,d0        ; Low bit in both word halves clear
  1099.         lea    wrk_theta(pc),a0
  1100.         and.l    d0,(a0)+    ; Zot, zot, zot...
  1101.         and.l    d0,(a0)+
  1102.         and.l    d0,(a0)+
  1103.  
  1104.     ;------    Copy new values to active variables.
  1105.         lea    wrk_delta(pc),a0
  1106.         lea    delta_x(pc),a1
  1107.         move.l    (a0)+,(a1)+
  1108.         move.l    (a0)+,(a1)+
  1109.         move.l    (a0)+,(a1)+
  1110.         move.l    (a0)+,(a1)+
  1111.         move.w    (a0),(a1)
  1112.  
  1113. UnWindOK    moveq    #0,d0        ; No error
  1114. UnWind        move.l    a4,sp        ; Restore stack pointer
  1115.         movem.l    (sp)+,d2/d7/a2-a5
  1116.         rts            ; Back to you, Brian...
  1117.  
  1118.  
  1119. ****************
  1120. * Gather decimal number.
  1121. *
  1122. GatherNum    moveq    #0,d0
  1123.         moveq    #0,d1
  1124.         moveq    #0,d2        ; negative flag
  1125.  
  1126.     ;------    Gather chars.  Test for whitespace first.
  1127. numloop        move.b    (a0)+,d1
  1128.         beq.s    11$        ; NULL; EOL
  1129.         cmp.b    #' ',d1
  1130.         beq.s    11$
  1131.         cmp.b    #9,d1        ; TAB
  1132.         beq.s    11$
  1133.         cmp.b    #10,d1        ; Newline
  1134.         beq.s    11$
  1135.  
  1136.     ;------    Check for unary minus.
  1137.         cmp.b    #'-',d1
  1138.         beq.s    22$
  1139.  
  1140.     ;------    Check for numeric.
  1141.         moveq    #ERR_BADVAL,d7
  1142.         cmp.b    #'0',d1
  1143.         blo.s    ParseError
  1144.         cmp.b    #'9',d1
  1145.         bhi.s    ParseError
  1146.  
  1147.     ;------    Accumulate numeric digit.  Overflow not tested.
  1148.         mulu    #10,d0
  1149.         sub.b    #'0',d1
  1150.         add.w    d1,d0
  1151.         bra.s    numloop
  1152.  
  1153.     ;------    Flip sense of minus sign.  We don't check for multiple
  1154.     ;------    instances.
  1155. 22$        not.b    d2
  1156.         bra.s    numloop
  1157.  
  1158.     ;------    Whitespace encountered; return to parser for storage.
  1159. 11$        tst.b    d2        ; This number negative?
  1160.         beq.s    110$
  1161.         neg.w    d0        ; Yep, turn it over.
  1162. 110$
  1163.         rts
  1164.  
  1165.  
  1166. ****************
  1167. * Short routine to report parsing errors
  1168. *
  1169. ParseError    move.l    ErrStrs(pc,d7.w),d0    ; Pointer to error string.
  1170.         bra.s    UnWind
  1171.  
  1172.  
  1173. ErrStrs        dc.l    SyntaxErr,BadVal,ModeMissing,MissingVal
  1174.         dc.l    ExtraVal,HelpStr
  1175.  
  1176. ERR_SYNTAX    EQU    0
  1177. ERR_BADVAL    EQU    4
  1178. ERR_NOMODE    EQU    8
  1179. ERR_MISSINGVAL    EQU    12
  1180. ERR_EXTRAVAL    EQU    16
  1181. ERR_HELP    EQU    20
  1182.  
  1183.  
  1184. ****************************************************************************
  1185. * Print string to CLI.  Pointer to string in D0.
  1186. *
  1187. PrintCLIStr    movem.l    d2/d3/a2/a6,-(sp)
  1188.         move.l    d0,a2        ; Save string pointer.
  1189.         move.l    DOSBase(pc),a6
  1190.         jsrlib    Output        ; Somewhere to print?
  1191.         move.l    d0,d1
  1192.         beq.s    99$        ; No, forget it
  1193.  
  1194.         move.l    a2,d2        ; Compute string length
  1195. 0$        tst.b    (a2)+
  1196.         bne.s    0$
  1197.         suba.l    d2,a2
  1198.         move.l    a2,d3
  1199.         subq.l    #1,d3
  1200.         jsrlib    Write        ; Write string
  1201. 99$
  1202.         movem.l    (sp)+,d2/d3/a2/a6
  1203.         rts
  1204.  
  1205.  
  1206. ****************************************************************************
  1207. * Bottom-of-frame interrupt routine.
  1208. *
  1209. BOFintr        moveq    #0,d0
  1210.         bset.l    #SIGBREAKB_CTRL_F,d0    ; F stands for Frame
  1211.         move.l    (4).w,a6
  1212.         jsrlib    Signal            ; Task ptr already in A1
  1213.  
  1214.         moveq    #0,d0
  1215.         rts
  1216.  
  1217.  
  1218. ****************************************************************************
  1219. * Something I added to make things more reliable.
  1220. *
  1221. ClearBSS    move.l    #EndBSS,d2
  1222.         lea    StartBSS,a2
  1223.         sub.l    a2,d2
  1224.         subq.w    #1,d2
  1225. 1$        clr.b    (a2)+
  1226.         dbra    d2,1$
  1227.  
  1228.         rts
  1229.  
  1230.  
  1231. ****************************************************************************
  1232. * Data!  (Yes, Captain?)
  1233. *
  1234. NumStars    dc.w    68
  1235.  
  1236. delta_x        dc.w    0    ; Star movement
  1237. delta_y        dc.w    0
  1238. delta_z        dc.w    4
  1239. theta_x        dc.w    0    ; Initial/current rotation angles
  1240. theta_y        dc.w    0
  1241. theta_z        dc.w    0
  1242. spin_x        dc.w    0    ; Spin velocities
  1243. spin_y        dc.w    0
  1244. spin_z        dc.w    0
  1245.  
  1246. wrk_delta    dc.w    0,0,0    ; Working areas for the parser
  1247. wrk_theta    dc.w    0,0,0
  1248. wrk_spin    dc.w    0,0,0
  1249.  
  1250. CurrentSinCos    dc.w    0    ; theta_x
  1251.         dc.w    0
  1252.         dc.w    0    ; theta_y
  1253.         dc.w    0
  1254.         dc.w    0    ; theta_z
  1255.         dc.w    0
  1256. IBase        dc.l    0
  1257. GBase        dc.l    0
  1258. DOSBase        dc.l    0
  1259. winptr        dc.l    0
  1260. Plane1ptr    dc.l    0
  1261. Plane2ptr    dc.l    0
  1262. sprdat        dc.l    0
  1263. WBStartMsg    dc.l    0
  1264. StarMsg        dc.l    0
  1265. StarSigMask    dc.l    0
  1266. StarSigs    dc.l    0
  1267. BackServ    dc.w    0
  1268.  
  1269. XCoords        dc.w    $FF37,$FED2,$6A,$FFF7,$C8,$CD,$FFF9,$132,$FF35
  1270.         dc.w    $FF9A,$FF7F,$16B,$EC,$FFF7,$186,$FF5A,$FF0D,$177
  1271.         dc.w    $FEAF,$6F,$FF5F,$FF22,$150,$2B,$FED5,$FEE3,$90,$AA
  1272.         dc.w    $FEBE,$13A,$12D,$FFA4,$FF49,$FEEE,$41,$164,$FF09
  1273.         dc.w    $8A,$FFE3,$D2,$FEBE,$13A,$12D,$FFA4,$FF49,$FEEE,$41
  1274.         dc.w    $164,$FF09,$8A,$FF46,$FF85,$154,$FF19,$60,$FF5C,$9B
  1275.         dc.w    $FFA8,$FF18,$158,$AE,$FF2F,$FE72,$21,$8C,$FE8B,$CF
  1276.         dc.w    $48,$FF7A,$137,$C8,$FED4
  1277. YCoords        dc.w    $FF5F,$FF22,$150,$2B,$FED5,$FEE3,$90,$AA,$FEBE,$13A
  1278.         dc.w    $12D,$FFA4,$FF49,$FEEE,$41,$164,$FF09,$8A,$FFE3,$D2
  1279.         dc.w    $FF37,$FED2,$6A,$FFF7,$C8,$CD,$FFF9,$132,$FF35
  1280.         dc.w    $FF9A,$FF7F,$16B,$EC,$FFF7,$186,$FF5A,$FF0D,$177
  1281.         dc.w    $FEAF,$6F,$177,$FEAF,$6F,$FF5F,$FF22,$150,$2B,$FED5
  1282.         dc.w    $FEE3,$90,$164,$FF09,$8A,$FFE3,$FF52,$FF2F,$18E,$21
  1283.         dc.w    $FF74,$FE8B,$CF,$FFB8,$86,$FEC9,$D2,$FF22,$94,$14D
  1284.         dc.w    $FE9B,$F4,$C8,$12C
  1285. ZCoords        dc.w    $FF52,$FF2F,$FE72,$21,$8C,$175,$FF31,$FFB8,$FF7A
  1286.         dc.w    $137,11,$153,$FF22,$94,$14D,$FE9B,$F4,$FEEC,$9B
  1287.         dc.w    $FF46,$FF85,$154,$FF19,$60,$FF5C,$9B,$FFA8,$FF18
  1288.         dc.w    $158,$FF61,$FE8F,$F8,$FEE7,$8C,$FF85,$48,$FEAC
  1289.         dc.w    $FF17,$6A,$13B,$FF01,$FF3A,$FFF9,7,$BE,$12B,$FED1
  1290.         dc.w    $FE94,$FC,$FF91,$CD,$FFF9,$132,$FF35,$FF9A,$FF7F
  1291.         dc.w    $16B,$EC,$FFF7,$186,$FED2,$6A,$FFF7,$C8,$CD,$FFF9
  1292.         dc.w    $132,$FF35,$FF9A,$FF7F,$96,$FF06
  1293.  
  1294.  
  1295. SineTable    dc.w    0,2,3,5,6,8,9,11
  1296.         dc.w    13,14,16,17,19,20,22,24
  1297.         dc.w    25,27,28,30,31,33,34,36
  1298.         dc.w    38,39,41,42,44,45,47,48
  1299.         dc.w    50,51,53,55,56,58,59,61
  1300.         dc.w    62,64,65,67,68,70,71,73
  1301.         dc.w    74,76,77,79,80,82,83,85
  1302.         dc.w    86,88,89,91,92,94,95,97
  1303.         dc.w    98,99,101,102,104,105,107,108
  1304.         dc.w    109,111,112,114,115,117,118,119
  1305.         dc.w    121,122,123,125,126,128,129,130
  1306.         dc.w    132,133,134,136,137,138,140,141
  1307.         dc.w    142,144,145,146,147,149,150,151
  1308.         dc.w    152,154,155,156,157,159,160,161
  1309.         dc.w    162,164,165,166,167,168,170,171
  1310.         dc.w    172,173,174,175,177,178,179,180
  1311.         dc.w    181,182,183,184,185,186,188,189
  1312.         dc.w    190,191,192,193,194,195,196,197
  1313.         dc.w    198,199,200,201,202,203,204,205
  1314.         dc.w    206,207,207,208,209,210,211,212
  1315.         dc.w    213,214,215,215,216,217,218,219
  1316.         dc.w    220,220,221,222,223,224,224,225
  1317.         dc.w    226,227,227,228,229,229,230,231
  1318.         dc.w    231,232,233,233,234,235,235,236
  1319.         dc.w    237,237,238,238,239,239,240,241
  1320.         dc.w    241,242,242,243,243,244,244,245
  1321.         dc.w    245,245,246,246,247,247,248,248
  1322.         dc.w    248,249,249,249,250,250,250,251
  1323.         dc.w    251,251,252,252,252,252,253,253
  1324.         dc.w    253,253,254,254,254,254,254,255
  1325.         dc.w    255,255,255,255,255,255,256,256
  1326.         dc.w    256,256,256,256,256,256,256,256
  1327.         dc.w    256,256,256,256,256,256,256,256
  1328.         dc.w    256,256,256,255,255,255,255,255
  1329.         dc.w    255,255,254,254,254,254,254,253
  1330.         dc.w    253,253,253,252,252,252,252,251
  1331.         dc.w    251,251,250,250,250,249,249,249
  1332.         dc.w    248,248,248,247,247,246,246,245
  1333.         dc.w    245,245,244,244,243,243,242,242
  1334.         dc.w    241,241,240,239,239,238,238,237
  1335.         dc.w    237,236,235,235,234,233,233,232
  1336.         dc.w    231,231,230,229,229,228,227,227
  1337.         dc.w    226,225,224,224,223,222,221,220
  1338.         dc.w    220,219,218,217,216,215,215,214
  1339.         dc.w    213,212,211,210,209,208,207,207
  1340.         dc.w    206,205,204,203,202,201,200,199
  1341.         dc.w    198,197,196,195,194,193,192,191
  1342.         dc.w    190,189,188,186,185,184,183,182
  1343.         dc.w    181,180,179,178,177,175,174,173
  1344.         dc.w    172,171,170,168,167,166,165,164
  1345.         dc.w    162,161,160,159,157,156,155,154
  1346.         dc.w    152,151,150,149,147,146,145,144
  1347.         dc.w    142,141,140,138,137,136,134,133
  1348.         dc.w    132,130,129,128,126,125,123,122
  1349.         dc.w    121,119,118,117,115,114,112,111
  1350.         dc.w    109,108,107,105,104,102,101,99
  1351.         dc.w    98,97,95,94,92,91,89,88
  1352.         dc.w    86,85,83,82,80,79,77,76
  1353.         dc.w    74,73,71,70,68,67,65,64
  1354.         dc.w    62,61,59,58,56,55,53,51
  1355.         dc.w    50,48,47,45,44,42,41,39
  1356.         dc.w    38,36,34,33,31,30,28,27
  1357.         dc.w    25,24,22,20,19,17,16,14
  1358.         dc.w    13,11,9,8,6,5,3,2
  1359.         dc.w    0,-2,-3,-5,-6,-8,-9,-11
  1360.         dc.w    -13,-14,-16,-17,-19,-20,-22,-24
  1361.         dc.w    -25,-27,-28,-30,-31,-33,-34,-36
  1362.         dc.w    -38,-39,-41,-42,-44,-45,-47,-48
  1363.         dc.w    -50,-51,-53,-55,-56,-58,-59,-61
  1364.         dc.w    -62,-64,-65,-67,-68,-70,-71,-73
  1365.         dc.w    -74,-76,-77,-79,-80,-82,-83,-85
  1366.         dc.w    -86,-88,-89,-91,-92,-94,-95,-97
  1367.         dc.w    -98,-99,-101,-102,-104,-105,-107,-108
  1368.         dc.w    -109,-111,-112,-114,-115,-117,-118,-119
  1369.         dc.w    -121,-122,-123,-125,-126,-128,-129,-130
  1370.         dc.w    -132,-133,-134,-136,-137,-138,-140,-141
  1371.         dc.w    -142,-144,-145,-146,-147,-149,-150,-151
  1372.         dc.w    -152,-154,-155,-156,-157,-159,-160,-161
  1373.         dc.w    -162,-164,-165,-166,-167,-168,-170,-171
  1374.         dc.w    -172,-173,-174,-175,-177,-178,-179,-180
  1375.         dc.w    -181,-182,-183,-184,-185,-186,-188,-189
  1376.         dc.w    -190,-191,-192,-193,-194,-195,-196,-197
  1377.         dc.w    -198,-199,-200,-201,-202,-203,-204,-205
  1378.         dc.w    -206,-207,-207,-208,-209,-210,-211,-212
  1379.         dc.w    -213,-214,-215,-215,-216,-217,-218,-219
  1380.         dc.w    -220,-220,-221,-222,-223,-224,-224,-225
  1381.         dc.w    -226,-227,-227,-228,-229,-229,-230,-231
  1382.         dc.w    -231,-232,-233,-233,-234,-235,-235,-236
  1383.         dc.w    -237,-237,-238,-238,-239,-239,-240,-241
  1384.         dc.w    -241,-242,-242,-243,-243,-244,-244,-245
  1385.         dc.w    -245,-245,-246,-246,-247,-247,-248,-248
  1386.         dc.w    -248,-249,-249,-249,-250,-250,-250,-251
  1387.         dc.w    -251,-251,-252,-252,-252,-252,-253,-253
  1388.         dc.w    -253,-253,-254,-254,-254,-254,-254,-255
  1389.         dc.w    -255,-255,-255,-255,-255,-255,-256,-256
  1390.         dc.w    -256,-256,-256,-256,-256,-256,-256,-256
  1391.         dc.w    -256,-256,-256,-256,-256,-256,-256,-256
  1392.         dc.w    -256,-256,-256,-255,-255,-255,-255,-255
  1393.         dc.w    -255,-255,-254,-254,-254,-254,-254,-253
  1394.         dc.w    -253,-253,-253,-252,-252,-252,-252,-251
  1395.         dc.w    -251,-251,-250,-250,-250,-249,-249,-249
  1396.         dc.w    -248,-248,-248,-247,-247,-246,-246,-245
  1397.         dc.w    -245,-245,-244,-244,-243,-243,-242,-242
  1398.         dc.w    -241,-241,-240,-239,-239,-238,-238,-237
  1399.         dc.w    -237,-236,-235,-235,-234,-233,-233,-232
  1400.         dc.w    -231,-231,-230,-229,-229,-228,-227,-227
  1401.         dc.w    -226,-225,-224,-224,-223,-222,-221,-220
  1402.         dc.w    -220,-219,-218,-217,-216,-215,-215,-214
  1403.         dc.w    -213,-212,-211,-210,-209,-208,-207,-207
  1404.         dc.w    -206,-205,-204,-203,-202,-201,-200,-199
  1405.         dc.w    -198,-197,-196,-195,-194,-193,-192,-191
  1406.         dc.w    -190,-189,-188,-186,-185,-184,-183,-182
  1407.         dc.w    -181,-180,-179,-178,-177,-175,-174,-173
  1408.         dc.w    -172,-171,-170,-168,-167,-166,-165,-164
  1409.         dc.w    -162,-161,-160,-159,-157,-156,-155,-154
  1410.         dc.w    -152,-151,-150,-149,-147,-146,-145,-144
  1411.         dc.w    -142,-141,-140,-138,-137,-136,-134,-133
  1412.         dc.w    -132,-130,-129,-128,-126,-125,-123,-122
  1413.         dc.w    -121,-119,-118,-117,-115,-114,-112,-111
  1414.         dc.w    -109,-108,-107,-105,-104,-102,-101,-99
  1415.         dc.w    -98,-97,-95,-94,-92,-91,-89,-88
  1416.         dc.w    -86,-85,-83,-82,-80,-79,-77,-76
  1417.         dc.w    -74,-73,-71,-70,-68,-67,-65,-64
  1418.         dc.w    -62,-61,-59,-58,-56,-55,-53,-51
  1419.         dc.w    -50,-48,-47,-45,-44,-42,-41,-39
  1420.         dc.w    -38,-36,-34,-33,-31,-30,-28,-27
  1421.         dc.w    -25,-24,-22,-20,-19,-17,-16,-14
  1422.         dc.w    -13,-11,-9,-8,-6,-5,-3,-2
  1423.  
  1424.  
  1425. colors        dc.w    0,$336,$669,$CCF
  1426.  
  1427. GfxName        dc.b    'graphics.library',0
  1428. IntuiName    dc.b    'intuition.library',0
  1429. DOSName        dc.b    'dos.library',0
  1430. ESName        dc.b    'EuroStars',0
  1431. ESPortName    dc.b    'EUROSTARS',0    ; ARexx wants uppercase.  Sigh...
  1432.  
  1433.  
  1434. ****************
  1435. * Error strings
  1436. *
  1437. SyntaxErr    dc.b    "Syntax error.",10,0
  1438. BadVal        dc.b    "Bad value.",10,0
  1439. ModeMissing    dc.b    "Must specify M, R, or S before XYZ.",10,0
  1440. MissingVal    dc.b    "Expecting more values.",10,0
  1441. ExtraVal    dc.b    "Unexpected extra value.",10,0
  1442.         dc.b    "$VER: "
  1443. HelpStr        dc.b    "ES 1.0 (12.5.92) -- EuroStars",10
  1444.         dc.b    "Written by Leo L. Schwab.",10,10
  1445.         dc.b    "Usage:",10
  1446.         dc.b    9,"ES [MRS][XYZ] <value> [<value> ... ]",10
  1447.         dc.b    9,"ES B",9,"; Run as background server",10
  1448.         dc.b    9,"ES Q",9,"; Quit (ARexx only)",10,10
  1449.         dc.b    "ARexx port name is EUROSTARS.",10,0
  1450.  
  1451.  
  1452. ****************
  1453. * Static structure definitions.
  1454. *
  1455.         cnop    0,4
  1456.  
  1457.     ;------    NewScreen
  1458. scr_def        dc.w    0,0
  1459.         dc.w    352,230
  1460.         dc.w    2
  1461.         dc.b    0,1
  1462.         dc.w    0
  1463.         dc.w    CUSTOMSCREEN!SCREENQUIET
  1464.         dc.l    0
  1465.         dc.l    ESName
  1466.         dc.l    0
  1467.         dc.l    0
  1468.  
  1469.     ;------    NewWindow
  1470. windef        dc.w    0,0
  1471.         dc.w    352,230
  1472.         dc.b    -1,-1
  1473.         dc.l    MOUSEBUTTONS
  1474.         dc.l    SMART_REFRESH!BACKDROP!BORDERLESS!ACTIVATE
  1475.         dc.l    0
  1476.         dc.l    0
  1477.         dc.l    0
  1478. scrptr        dc.l    0
  1479.         dc.l    0
  1480.         dc.w    0,0,0,0
  1481.         dc.w    CUSTOMSCREEN
  1482.  
  1483.     ;------    MessagePort
  1484. mport        dc.l    0,0        ; LN_SUCC, LN_PRED
  1485.         dc.b    NT_MSGPORT    ; LN_TYPE
  1486.         dc.b    0        ; LN_PRI
  1487.         dc.l    ESPortName    ; LN_NAME
  1488.         dc.b    PA_SIGNAL    ; MP_FLAGS
  1489. mpsigbit    dc.b    -1        ; MP_SIGBIT
  1490. mpsigtask    dc.l    0        ; MP_SIGTASK
  1491.         ds.b    LH_SIZE        ; MP_MSGLIST,LH_SIZE
  1492.  
  1493.     ;------    Startup Message
  1494. startmsg    dc.l    0,0        ; LN_SUCC, LN_PRED
  1495.         dc.b    NT_MESSAGE    ; LN_TYPE
  1496.         dc.b    0        ; LN_PRI
  1497.         dc.l    ESName        ; LN_NAME
  1498.         dc.l    mport        ; MN_REPLYPORT
  1499.         dc.w    MN_SIZE        ; MN_LENGTH
  1500.  
  1501.     ;------    Interrupt structure
  1502. BOFintrnode    dc.l    0,0        ; LN_SUCC, LN_PRED
  1503.         dc.b    NT_INTERRUPT    ; LN_TYPE
  1504.         dc.b    0        ; LN_PRI
  1505.         dc.l    ESName        ; LN_NAME
  1506. StarTask    dc.l    0        ; IS_DATA
  1507.         dc.l    BOFintr        ; IS_CODE
  1508.  
  1509.  
  1510. ****************************************************************************
  1511. * Uninitialized data
  1512. *
  1513.         SECTION EuroStars,BSS
  1514. StartBSS:
  1515.  
  1516. MyCopList    ds.b    ucl_SIZEOF
  1517. XBuff        ds.w    150
  1518. YBuff        ds.w    150
  1519. ZBuff        ds.w    150
  1520. PlaneOffsets    ds.w    150
  1521.  
  1522. EndBSS:
  1523.         END
  1524.